package com.example.demo.day.config.learn.designBook.secondDay.part4;

import com.example.demo.day.config.learn.designBook.secondDay.part1.IBook;
import com.example.demo.day.config.learn.designBook.secondDay.part1.NovelBook;

import java.text.NumberFormat;
import java.util.ArrayList;

public class BookStore {

    private final static ArrayList<IBook> bookList = new ArrayList<IBook>();
    //static静态模块初始化数据，实际项目中一般是由持久层完成

    static {
        bookList.add(new NovelBook("天龙八部", 3200, "金庸"));
        bookList.add(new NovelBook("巴黎圣母院", 5600, "雨果"));
        bookList.add(new NovelBook("悲惨世界", 3500, "雨果"));
        bookList.add(new NovelBook("射雕英雄传", 4300, "金庸"));
        //增加计算机书籍
        bookList.add(new ComputerBook("Think in Java", 4300, "Bruce Eckel", "编程语言"));
    }

    //模拟书店买书
    public static void main(String[] args) {
        NumberFormat format = NumberFormat.getCurrencyInstance();
        format.setMaximumFractionDigits(2);
        System.out.println("---------------------书店卖出去的书籍记录如下: ----------------------");
        for (IBook book: bookList) {
            System.out.println("书籍名称： " + book.getName() + "\t书籍作者: " + book.getAuthor() + "\t书籍价格: " + format.format(book.getPrice()/100.0) + "元");
//            System.out.println("书籍名称： " + book.getName() + "\t书籍作者: " + book.getAuthor() + "\t书籍价格: " + book.getPrice()/100.0 + "元");
        }
    }
}
